//
//  AppDelegate.m
//  AudioBook_A
//
//  Created by Sansan on 15/4/10.
//  Copyright (c) 2015年 Sansan. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

// 初始化消息通知
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center addObserver:self selector:@selector(receiveNotifica:)
                       name:@"heiyejianglin" object:nil];
        
        NSNotificationCenter *center2 = [NSNotificationCenter defaultCenter];
        [center2 addObserver:self selector:@selector(receiveNotifica2:) name:@"limingjianglin" object:nil];
        
    }
    return self;
}

- (void)receiveNotifica:(NSNotification *)center
{
    //   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    //1.UIView动画
    [UIView animateWithDuration:0.6 animations:^{
        
        self.nightImage.frame = CGRectMake(self.window.bounds.size.width * 26.66 / 100, self.window.bounds.size.height * 36.73 / 100, self.window.bounds.size.width * 46.66 / 100, self.window.bounds.size.height * 26.23 / 100);
        self.nigView.hidden = NO;
        
    }];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.nightImage.frame = CGRectMake(self.window.bounds.size.width, self.window.bounds.size.height * 36.73 / 100, self.window.bounds.size.width * 46.66 / 100, self.window.bounds.size.height * 26.23 / 100);
        }];
        
        
    });
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        UIImage *image = [UIImage imageNamed:@"taiyang.png"];
        self.nightImage.image = image;
    });
}




- (void)receiveNotifica2:(NSNotification *)center
{
    
    // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    //1.UIView动画
    [UIView animateWithDuration:0.6 animations:^{
        
        self.nightImage.frame = CGRectMake(self.window.bounds.size.width * 26.66 / 100, self.window.bounds.size.height * 36.73 / 100, self.window.bounds.size.width * 46.66 / 100, self.window.bounds.size.height * 26.23 / 100);
    }];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.nightImage.frame = CGRectMake(- self.window.bounds.size.width, self.window.bounds.size.height * 36.73 / 100, self.window.bounds.size.width * 46.66 / 100, self.window.bounds.size.height * 26.23 / 100);
            self.nigView.hidden = YES;
        }];
        
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        UIImage *image = [UIImage imageNamed:@"yueliang1.png"];
        self.nightImage.image = image;
        
    });
    
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];
    
    AudioBookViewController *audioVC = [[AudioBookViewController alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:audioVC];

    DDMenuController *ddMenuController = [[DDMenuController alloc] initWithRootViewController:naVC];
    
    
    self.menuController = ddMenuController;
    
    LeftViewController *leftController = [[LeftViewController alloc] init];
    ddMenuController.leftViewController = leftController;
    
    self.window.rootViewController = ddMenuController;
    
    [self.window addSubview:[AudioPlayerHandle shareHandle].AudioPlayer];
    
    // 动画通知  ****************************//
    [NSThread sleepForTimeInterval:2];
    
    self.nightImage = [[UIImageView alloc] initWithFrame:CGRectMake(- self.window.bounds.size.width, self.window.bounds.size.height * 36.73 / 100, self.window.bounds.size.width * 46.66 / 100, self.window.bounds.size.height * 26.23 / 100)];
    
    
    self.nigView = [[UIView alloc] initWithFrame:self.window.bounds];
    self.nigView.userInteractionEnabled = NO;
    self.nigView.hidden = YES;
    self.nigView.backgroundColor = [UIColor blackColor];
    self.nigView.alpha = 0.6;
    [self.window addSubview:self.nigView];
    [_nigView release];
    
    
    
    UIImage *nigImage = [UIImage imageNamed:@"yueliang1.png"];
    self.nightImage.image = nigImage;
    [self.window addSubview:self.nightImage];
    [_nightImage release];
    
    // 是否显示阴影, 否
    [self.drawerController setShowsShadow:NO];
    
    // 给视图控制器一个恢复标识
    [self.drawerController setRestorationIdentifier:@"MMDrawer"];
    // 设置左视图宽度
    [self.drawerController setMaximumLeftDrawerWidth:[UIScreen mainScreen].bounds.size.width / 3 * 2];
    // 设置打开抽屉的状态为全部
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    // 设置关闭抽屉的状态效果为全部
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window setRootViewController:self.drawerController];
    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
